<template>
  <halo-dialog :visible="visible" @cancel="cancel">
    <div class="confirm-content">
      <div class="close-btn" @click="visible = false">
        <i class="iconfont icon-close"></i>
      </div>
      <div class="title">{{ options.title }}</div>
      <div class="content">{{ options.content }}</div>
      <footer class="footer">
        <div class="btn" @click="cancel">取消</div>
        <div class="btn primary" @click="ok">确认</div>
      </footer>
    </div>
  </halo-dialog>
</template>

<script>
import HaloDialog from '@/common/halo-dialog';

const defaults = {
  title: '确认删除',
  content: '删除后将不可以恢复',
  okText: '确认',
  cancelText: '取消',
};

export default {
  components: {
    HaloDialog,
  },
  data() {
    return {
      options: defaults,
      visible: false,
      resolve: null,
      reject: '',
    };
  },
  methods: {
    show(options = {}, resolve, reject) {
      options && (this.options = { ...defaults, ...options });
      console.log(resolve, typeof resolve);
      typeof resolve === 'function' && (this.resolve = resolve);
      typeof reject === 'function' && (this.reject = reject);
      this.visible = true;
    },
    hide() {
      this.visible = false;
      this.resolve = null;
      this.reject = null;
    },
    ok() {
      this.visible = false;
      this.resolve && this.resolve();
    },
    cancel() {
      this.visible = false;
      this.reject && this.reject();
    },
  },
};
</script>

<style lang="less" scoped>
.confirm-content {
  width: 360px;
  height: 210px;
  background: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  .title {
    font-size: 20px;
    font-weight: 600;
    color: #222222;
    line-height: 28px;
    padding-bottom: 20px;
  }
  .content {
    font-size: 14px;
    font-weight: 400;
    color: #222222;
    line-height: 20px;
    padding-bottom: 30px;
  }
  .footer {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .btn {
    width: 96px;
    height: 40px;
    background: #ffffff;
    border-radius: 3px;
    border: 1px solid #dfdfdf;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    margin: 0 15px;
    &.primary {
      color: white;
      background-color: #fd236b;
      border-color: #fd236b;
    }
  }
}
.close-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  &:hover {
    opacity: 0.8;
  }
  .iconfont {
    font-size: 18px;
  }
}
</style>